<docs>
  ## 发布新职位
</docs>
<template>
  <div class="wrap" ref="wrap">
    <my-bread title="发布新职位" :goback="true"></my-bread>
    <co-form :model="data" :rules="rules" ref="form">
      <co-position
        label="招聘岗位"
        v-model="data.gwmc"
        prop="gwmc"
        :gwbh.sync="data.gwbm"
      ></co-position>
      <co-input prop="zrs" label="招聘人数"
        v-model="data.zrs"></co-input>
      <date-inteval prop="fbkssj" label="发布时间" v-model="data.fbkssj" :maxDate.sync="data.fbjzsj"></date-inteval>
      <co-select
        prop="ygxs"
        label="用工形式"
        v-model="data.ygxs"
        :list="codeTable.zyjs_d_dwygxs"
      ></co-select>
      <co-select
        v-show="xclxFlag"
        prop="xclx"
        label="薪酬类型"
        v-model="data.xclx"
        :list="xclx"
      ></co-select>
      <co-input prop="zdnx" v-show="nx" label="最低年薪" v-model="data.zdnx" placeholder="请输入最低年薪"></co-input>
      <co-input
        v-show="nx"
        prop="zgnx"
        label="最高年薪"
        v-model="data.zgnx"
        placeholder="请输入最高年薪"
      ></co-input>
      <co-input prop="zdyx" v-show="yx" label="最低月薪" v-model="data.zdyx" placeholder="请输入最低月薪"></co-input>
      <co-input
        v-show="yx"
        prop="zgyx"
        label="最高月薪"
        v-model="data.zgyx"
        placeholder="请输入最高月薪"
      ></co-input>

      <co-input prop="zdsx" v-show="sx" label="最低时薪" v-model="data.zdsx" placeholder="请输入最低时薪"></co-input>
      <co-input
        v-show="sx"
        prop="zgsx"
        label="最高时薪"
        v-model="data.zgsx"
        placeholder="请输入最高时薪"
      ></co-input>
      <co-input prop="ycxlwf" v-show="ycxlwf" label="一次性劳务费" v-model="data.ycxlwf" placeholder="请输入一次性劳务费"></co-input>
      <div class="line" v-if="codeTable.zyjs_d_gzdq.length > 0">
        <tree-select label="工作地区" :items="codeTable.zyjs_d_gzdq" v-model="data.gzdq" ></tree-select>
      </div>

      <!-- <co-input prop="gzdd" label="工作地点" v-model="data.gzdd"></co-input> -->

      <co-select
        label="是否公开联系人"
        prop='sfgklxr'
        v-model="data.sfgklxr"
        :list="sfgklxrList"
      ></co-select>
      <co-input v-show="lxr" prop="zplxr" label="招聘联系人" v-model="data.zplxr"></co-input>
      <co-input v-show="lxr" prop="zplxrsj" label="招聘联系人手机" v-model="data.zplxrsj"></co-input>
      <co-select prop="whcd" label="文化程度" v-model="data.whcd"
        :list="codeTable.zyjsww_d_gwwhcd"></co-select>
      <co-level-picker
          prop="sxzy"
          label="所学专业"
          v-model="data.sxzy"
          v-show="sxzy"
          :flag="math"
          :table-name="unTableName"
        ></co-level-picker>
      <!-- <div class="weui-cell zprs">
        <div class="weui-cell__hd">
          <label class="weui-label">年龄要求(岁)</label>
        </div>
        <div class="weui-cell__bd">
          <input prop="zxnl" type="text" class="weui-input" maxlength="2" v-model="data.zxnl">至
          <input prop="zdnl" type="text" class="weui-input" maxlength="2" v-model="data.zdnl">
        </div>
      </div> -->
      <co-textarea prop="gwzz" label="岗位职责" v-model="data.gwzz"></co-textarea>
      <co-textarea prop="gwyq" label="岗位要求" v-model="data.gwyq"></co-textarea>
      <!-- <co-textarea prop="fldy" label="福利待遇" v-model="data.fldy"></co-textarea> -->
      <div v-if="codeTable.zyjs_d_fldylx.length>0">
        <tree-select prop="fldy" label="福利待遇" :items="codeTable.zyjs_d_fldylx" v-model="data.fldy" ></tree-select>
      </div>
      <co-textarea prop="qtfldy" label="其他福利待遇说明" v-model="data.qtfldy" v-if="fldyqt"></co-textarea>
      <div v-if="codeTable.zyjs_d_zyqt.length>0">
        <tree-select prop="zyqt" label="招用群体" :items="codeTable.zyjs_d_zyqt" v-model="data.zyqt" ></tree-select>
      </div>
      <div v-if="codeTable.zyjs_d_gwlx_xz.length>0">
        <tree-select prop="gwlx" label="岗位类型" :items="codeTable.zyjs_d_gwlx_xz" :lack.sync='lackList' v-model="data.gwlx" ></tree-select>
      </div>
    </co-form>
    <div class="btn-wrap">
      <button class="weui-btn weui-btn_primary" @click.prevent="save" type="button">发布职位</button>
    </div>

  </div>
</template>
<script>
import coForm from 'base/form/form';
import coInput from 'base/form/input';
import coSelect from 'base/form/select';
import coPosition from "base/form/position1";
import coTextarea from "base/form/textarea/textarea";
import { validator } from 'common/js/valid';
import coLevelPicker from 'base/form/levelPicker';
import dateInteval from "base/form/dateInteval";
import treeSelect from "base/form/treeSelect";

export default {
  name: 'editDetail',
  components: { coForm, coInput, coSelect, coLevelPicker, coPosition, coTextarea, treeSelect,dateInteval },
  data() {
    return {
      palseShow:false,//隐藏请选择
      lackList:true,//岗位类型选择显示
      dele: false,
      lxr: false, //联系人显示
      unTableName:"",//文化程度 专业表明
      sxzy:false, //所学专业隐藏
      deleteList:[],
      sfgklxrList: [{ dmid: "01", dmmc: "是" },{ dmid: "02", dmmc: "否" }],
      data: {
        sfgklxr:'',
        ywcz: '1',//业务操作默认1
        gwbm: '', // 岗位编码
        gwmc: '', // 岗位名称
        zrs:"", //招聘人数
        fbkssj:"",//发布开始时间
        fbjzsj:"",//发布截止时间
        ygxs: "", // 用工形式
        xclx: "", // 薪酬类型
        zgnx:"", //最高年薪
        zdnx:"", //最低年薪
        zgyx:"", //最高月薪
        zdyx:"", //最低月薪
        zgsx:"", //最高时薪
        zdsx:"", //最低时薪
        ycxlwf:"", //一次性劳务费
        gzdq: "", // 工作地区
        gzdd: "", // 工作地点
        zplxr: "", // 招聘联系人
        zplxrsj:"",//招聘联系人电话
        whcd:"",//文化程度
        sxzy:"",//所学专业
        // zxnl:"",//最小年龄
        // zdnl:"",//最大年龄
        gwzz: "", // 岗位职责
        gwyq:"",//岗位要求
        zyqt:"",//招用群体
        fldy:"", //福利待遇
        gwlx:"" //岗位类型
      },
      rules: {
        gwmc: validator("64,least,招聘岗位,false"), // 岗位名称
        zrs: validator('4,"number","招聘人数",false'), // 招聘人数
        fbkssj: validator("10,full,发布时间,false"), // 发布时间
        // gzdq: validator("12,full,工作地区,false"), // 工作地区
        // gzdd: validator('128,"full","工作地点",true'), // 工作地点
        ygxs: validator('2,"full","用工形式",false'), // 用工形式
        xclx: validator('2,"full","薪酬类型",true'), // 薪酬类型
        zgyx: validator('7,"number","最高月薪",true'), // 最高月薪
        zdyx: validator('7,"number","最低月薪",true'), // 最低月薪
        zgsx: validator('7,"number","最高时薪",true'), // 最高时薪
        zdsx: validator('7,"number","最低时薪",true'), // 最低时薪
        zgnx: validator('7,"number","最高年薪",true'), // 最高年薪
        zdnx: validator('7,"number","最低年薪",true'), // 最低年薪
        ycxlwf: validator('7,"normal","一次性劳务费",true'), // 一次性劳务费
        zplxr: validator("32,full,招聘联系人,true"), // 招聘联系人
        zplxrsj: validator("11,normal,招聘联系人电话,true"), // 招聘联系人电话
        whcd: validator('2,"full","文化程度",true'), // 文化程度
        // zxnl: validator('2,"number","最小年龄",true'), // 最小年龄
        // zdnl: validator('2,"number","最大年龄",true'), // 最大年龄
        gwzz: validator('2000,"normal","岗位职责",false'), // 岗位职责 按照字符判断，2000字符为1000文字
        gwyq: validator('2000,"normal","岗位要求",true'), // 岗位要求
        qtfldy: validator('1024,"normal","其他福利待遇",true'), // 其他福利待遇
        fldy: validator('500,"normal","福利待遇",true'), // 福利待遇
        zyqt: validator('255,"normal","招用群体",true'), // 招用群体
        gwlx: validator('255,"normal","岗位类型",true'), // 岗位类型
        sxzy: validator('168,"full","所学专业",true'), //所学专业
        sfgklxr: validator('2,"full","是否公开联系人",false'), //是否公开联系人
      },
      nx: false,
      yx: false,
      sx: false,
      ycxlwf: false,
      fldyqt: false,
      // xclx: [{ dmid: "01", dmmc: "年薪" },{ dmid: "02", dmmc: "月薪" }],
      xclx: [],
      ygxs:"",
      math:"1",//级联选择--专业标识防止出现点击其他跟着改变BUG
      xclxFlag: false,//全职显示年薪，月薪
      codeTable: {
        zyjs_d_dwygxs:[], // 用工形式
        zyjs_d_gzdq:[], // 工作地区
        zyjsww_d_gwwhcd: [], // 文化程度
        zyjs_d_zyqt: [], //招用群体
        zyjs_d_gwlx_xz: [], //岗位类型
        zyjs_d_fldylx: [] //福利待遇
      },
    };
  },
  watch:{
    "data.sfgklxr":function (val){
      this.$nextTick(_=>{
        if (val === '02') {
          this.lxr = false;
          this.data.zplxr = '';
          this.data.zplxrsj = '';
        } else if (val === '01') {
          this.lxr = true;
        }
      })
    },
    'data.whcd': function (val) {
      if(!val) return
      this.sxzy = true;
      if (val <= 17) {
        this.unTableName = "zyjs_d_yjs";
      } else if (val == "20") {
        this.unTableName = "zyjs_d_bk";
      } else if (val == "30") {
        this.unTableName = "zyjs_d_zk";
      } else if (val == "40") {
        this.unTableName = "zyjs_d_zz";
      }else {
        this.sxzy = false;
      }
    },
    "data.ygxs": function watcher(val) {
      this.$nextTick(_=>{
        if (val == '40') {
          this.sx = true;
          return
        }
        if (this.ygxs !== val) {
          this.data.xclx = "";
        }
      })
      this.ycxlwf = false;
      this.xclxFlag = false;
      this.sx = false;
      this.yx = false;
      this.nx = false;
      if(!val) return
      if(val == '10'){
        this.xclx= [{ dmid: "01", dmmc: "年薪" },{ dmid: "02", dmmc: "月薪" }];
        this.xclxFlag = true;
      }else if (val === "40") {
        this.sx = true;
        this.data.xclx = "03";
      } else {
        this.xclx= [{ dmid: "02", dmmc: "月薪" },{ dmid: "03", dmmc: "时薪" },{ dmid: "04", dmmc: "一次性劳务费" }];
        this.xclxFlag = true;
        this.ycxlwf = false;
      }
    },
    "data.xclx": function (val) {
      if(!val){
        this.ycxlwf = false;
        this.yx = false;
        this.sx = false;
        this.nx = false;
      }else if(val == '01'){
        this.nx = true;
        this.yx = false;
        this.sx = false;
        this.ycxlwf = false;
      }else if(val == '02'){
        this.yx = true;
        this.sx = false;
        this.nx = false;
        this.ycxlwf = false;
      } else if(val == '03'){
        this.sx = true;
        this.yx = false;
        this.nx = false;
        this.ycxlwf = false;
      } else if(val == '04'){
        this.yx = false;
        this.nx = false;
        this.sx = false;
        this.ycxlwf = true
      }
    },
    'data.fldy': function (val) {
      this.fldyqt = val.includes("11")?true : false;
    }
  },
  methods: {
    save() {
      Object.keys(this.data).forEach(item => {
        if(this.data[item] instanceof Array){
          this.data[item] = this.data[item].toString();
        }
      });
      this.$refs.form.validate(() => {
        if ((this.data.ygxs== '10' || this.data.ygxs== '20'|| this.data.ygxs== '30') && !this.data.xclx) {
          this.$refs.form.errorMsg = '薪酬类型不能为空！';
          return;
        }
        if (!this.data.gzdq) {
          this.$refs.form.errorMsg = '工作地区不能为空！';
          return;
        }
        if(this.data.sfgklxr == '01' && !this.data.zplxr || this.data.sfgklxr == '02' && this.data.zplxr){
          this.$refs.form.errorMsg = '招聘联系人不能为空！';
          return;
        }
        if(this.data.sfgklxr == '01' && !this.data.zplxrsj ||this.data.sfgklxr == '02' && this.data.zplxrsj ){
          this.$refs.form.errorMsg = '招聘联系人手机不能为空！';
          return;
        }
        // if (this.data.zxnl && this.data.zxnl < '16') {
        //   this.$refs.form.errorMsg = '最小年龄不得小于16岁！';
        //   return;
        // }
        // if (this.data.zdnl && this.data.zdnl > '60') {
        //   this.$refs.form.errorMsg = '最大年龄不得大于60岁！';
        //   return;
        // }
        if (this.data.xclx == '01') {
          this.data.zdyx = this.data.zgyx = this.data.zgsx = this.data.zdsx = this.data.ycxlwf ='';
        } else if (this.data.xclx == '02'){
          this.data.zdnx = this.data.zgnx = this.data.zgsx = this.data.zdsx = this.data.ycxlwf ='';
        } else if (this.data.xclx == '03'){
          this.data.zdnx = this.data.zgnx = this.data.zgyx = this.data.zdyx = this.data.ycxlwf ='';
        } else {
          this.data.zdnx = this.data.zgnx = this.data.zgyx = this.data.zdyx =this.data.zgsx = this.data.zdsx ='';
        }
          this.POST_save();
      });
    
    },
    /* 获取代码表 */
    GET_codeTable() {
      const arrTableName = Object.keys(this.codeTable);
      this.$http.get('/dmbgl/dmblbCx', {
        params: {
          table_name: arrTableName.join()
        }
      }).then((res) => {
        this.getCodeTabled = true;
        const data = res.returnData.dmblb;
        arrTableName.forEach(item => {
          this.codeTable[item] = data[item];
        });
      });
    },
    /* 保存信息修改 */
    POST_save() {
      this.$confirm('确定发布职位？', '提示')
      .then(() => {
        this.$loading = true;
        this.$http
          .post("/dwgl/zpxxBc", this.data)
          .then(res => {
            const resData = res.returnData;
            this.$alert(resData.message, () => {
              const code = +resData.executeResult;
              if (code === 1) {
                this.$router.push({ path: "/vocation/vocation/inProgress" });
              }
            });
          })
          .finally(() => {
            this.$loading = false;
          });
      })
      .catch(() => {
        this.$toast('选择了取消');
      });
    },
    /*  查询基本信息 */
    GET_getInfo() {
      this.$loading = true;
      this.$http.get('/grgl/grxqCx').then(res => {
        const resData = res.returnData;
        this.data = resData.jbxx;
        // this.nextFlag = resData.sfyqzdj == '0'? false: true;
        // 行政区划显示
        this.hjdxzqh_xs = this.data.hjdxzqh_xs;
        this.jzdxzqh_xs = this.data.jzdxzqh_xs;
        this.sxzy_xs = this.data.sxzy_xs;
        this.sxzy_chang = this.data.whcd;
      }).finally(() => {
        this.$loading = false;
      });
    },
    /* 返回基础信息 */
    backBase() {
      this.$router.go(-1);
    }
  },
  mounted(){
    this.data.sfgklxr = '01';
  },
  created() {
    // 获取代码表
    this.getCodeTabled = false;
    this.GET_codeTable();
    // 隐藏home按钮
    this.$store.commit('SET_VISIBLE_ALL', false);
  }
};
</script>
<style scoped lang="scss">
@import '~common/scss/var.scss';
.wrap {
  background: $color-bg;
  overflow: auto;
  .btn-wrap {
    display: flex;
    .weui-btn {
      margin: 20px auto;
      flex: 0 1 60%;
      margin-top: $margin-base;
    }
  }
  .zprs {
    .weui-label {
      text-align-last: justify;
      width: 240px;
      padding-right: $padding-base * 2;
      font-size: $font-size-small;
      box-sizing: border-box;
    }
    .weui-cell__bd {
      text-align: right;
      font-size: $font-size-base;
      input{
        display:inline-block;
        width: 45%;
      }
    }
  }
  .weui-btn_primary{
    background-color:#06A8F6;
  }
  .line{
    position: relative;
  }
}
</style>
